// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Break Block Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 58 : TYPE_BREAKBLOCK

// Function declarations
reserve function BreakBlock_DebugDraw
reserve function BreakBlock_DebugSpawn

// Static Values

// Tables

function BreakBlock_DebugDraw
	DrawSprite(0)
end function


function BreakBlock_DebugSpawn
	CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
end function


event ObjectMain
	switch object.state
	case 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			if object[currentPlayer].animation == ANI_JUMPING
				BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					object[currentPlayer].yvel = -0x30000
					object[currentPlayer].gravity = GRAVITY_AIR
					CreateTempObject(TypeName[Object Score], object[currentPlayer].value19, object.xpos, object.ypos)
					object[tempObjectPos].drawOrder = 4
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos -= 8
					object[tempObjectPos].iypos -= 8
					object[tempObjectPos].xvel = -0x20000
					object[tempObjectPos].yvel = -0x20000
					object[tempObjectPos].state = 1
					object[tempObjectPos].drawOrder = 5
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos += 8
					object[tempObjectPos].iypos -= 8
					object[tempObjectPos].xvel = 0x20000
					object[tempObjectPos].yvel = -0x20000
					object[tempObjectPos].state = 1
					object[tempObjectPos].drawOrder = 5
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos -= 8
					object[tempObjectPos].iypos += 8
					object[tempObjectPos].xvel = -0x10000
					object[tempObjectPos].yvel = -0x10000
					object[tempObjectPos].state = 1
					object[tempObjectPos].drawOrder = 5
					CreateTempObject(TypeName[Break Block], 0, object.xpos, object.ypos)
					object[tempObjectPos].ixpos += 8
					object[tempObjectPos].iypos += 8
					object[tempObjectPos].xvel = 0x10000
					object[tempObjectPos].yvel = -0x10000
					object[tempObjectPos].state = 1
					object[tempObjectPos].drawOrder = 5
					object.type = TypeName[Blank Object]
					switch object[currentPlayer].value19
					case 0
						player.score += 100
						break
					case 1
						player.score += 200
						break
					case 2
						player.score += 500
						break
					case 3
					case 4
					case 5
					case 6
					case 7
					case 8
					case 9
					case 10
					case 11
					case 12
					case 13
					case 14
						player.score += 1000
						break
					case 15
						player.score += 0x2710
						if stage.debugMode == 0
							CallNativeFunction2(SetAchievement, 3, 100)
						end if
						break
					end switch
					if object[currentPlayer].gravity == GRAVITY_AIR
						if object[currentPlayer].value19 < 15
							object[currentPlayer].value19++
						end if
					end if
					PlaySfx(SfxName[Block Break], 0)
				end if
			else
				BoxCollisionTest(C_BOX, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			end if
		next
		break
	case 1
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x3800
		if object.outOfBounds == 1
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
end event


event ObjectDraw
	DrawSprite(object.state)
end event


event ObjectStartup
	LoadSpriteSheet("MZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 317, 363)
	SpriteFrame(-8, -8, 16, 16, 317, 363)
	SetTableValue(TypeName[Break Block], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(BreakBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(BreakBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
